import React, {useState, createContext, useContext} from 'react';

// # createContext/useContext 解决了组件传值的问题
const CountContext = createContext()

function Counter() {
  let count = useContext(CountContext)
  return (<h3>子组件：{count}</h3>)
}

export default function () {
  const [count, setCount] = useState(0)

  return (
    <div>
      <h2>你点击了 {count} 次</h2>
      <button onClick={() => {
        setCount(count + 1)
      }}>点击
      </button>
      <hr/>
      <CountContext.Provider value={count}>
        <Counter/>
      </CountContext.Provider>
    </div>
  )
}
